package weaver.interfaces.zhlx.duss.action.purchasemodule.ec;

import com.weaver.general.BaseBean;
import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.interfaces.workflow.action.Action;
import weaver.interfaces.zhlx.duss.utils.EcUtil;
import weaver.soa.workflow.request.RequestInfo;

/**
 * @Title: ecology-idea
 * @Company: 泛微软件
 * @author: weaver.Dusongsong
 * @version: 1.0
 * @CreateDate: 2023-11-13
 * @Description: 辅料退库流程：如果选择的料件编号对应的明细1评估分类的有值的话，
 * 需要在OA里面自动生成新的批次号，批次号的规则见微信
 * @ModifyLog:
 **/
public class WeaFltklcBhAction extends BaseBean implements Action {
    @Override
    public String execute(RequestInfo requestInfo) {
        String requestid = requestInfo.getRequestid();
        String tablename = requestInfo.getRequestManager().getBillTableName();
        writeLog(">>>>>WeaFltklcBhAction>>>>>requestid=" + requestid);
        try {
            RecordSet rs = new RecordSet();
            rs.executeQuery("select id,sqrq from " + tablename + " where requestid=?", requestid);
            rs.next();
            String mainid = Util.null2String(rs.getString("id"));
            String sqrq = Util.null2String(rs.getString("sqrq"));
            String maxLsh = EcUtil.getMaxlshById(tablename+"_dt1");
            String year =sqrq.substring(0,4);
            String month =sqrq.substring(5,7);
            String date =sqrq.substring(8,10);
            int num = Util.getIntValue(maxLsh);
            rs.executeQuery("select * from "+tablename+"_dt1 where mainid=? and (lsh is null or lsh='') and (pgfl is not null or pgfl !='')",mainid);
            while (rs.next()){
                String id =Util.null2String(rs.getString("id"));
                String gcdm =Util.null2String(rs.getString("gcdm"));
                String wxbs =Util.null2String(rs.getString("wxbs"));
                String lsh = EcUtil.autoGenericCode(num+"",3);
                String pcbh = gcdm+year+month+date+wxbs+lsh;
                rs.executeUpdate("update "+tablename+"_dt1 set lsh=?,pcbh=? where id=?",lsh,pcbh,id);
                num++;
            }
            return Action.SUCCESS;
        } catch (Exception e) {
            writeLog(">>>>>WeaFltklcBhAction>>>>>Exception=" + e);
            requestInfo.getRequestManager().setMessageid("111111");
            requestInfo.getRequestManager().setMessagecontent("Action接口异常！");
            return Action.FAILURE_AND_CONTINUE;
        }
    }

}